package ext.tianma.bom.service;

import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import wt.org.WTUser;



@Controller
@RequestMapping(value="/selectUserController")
public class SelectUserController {

	
	/**
	 * 创建员工信息
	 * 
	 * @author Administrator
	 * 
	 * http://plmdev.tianma.cn/Windchill/app/selectUserController/newUserMessage
	 * [{"code":"B123455","name":"工号","email":"B123455@qq.com","mobile":"13813813813","firstName":"工号"}]
	 * 			
	 */
	@RequestMapping(value = "/newUserMessage", method = { RequestMethod.POST,
			RequestMethod.GET })
	public void newestPartMessage(@RequestBody String result,HttpServletResponse response) throws Exception {
		System.out.println("start=====>>>"+result);
		 List<WTUsers> users = JSON.parseArray(result, WTUsers.class);
		    for (WTUsers wtUsers : users) {
		    	String userName = wtUsers.getName();
				String fullName = wtUsers.getName();
				String email = wtUsers.getEmail();
				String userPhone = wtUsers.getMobile();
				String userNo = wtUsers.getCode();
				String firstName = wtUsers.getFirstName();
				WTUser resultUser = SelectUserService.createWTUser(userNo,userName, fullName, email,"121", userPhone, userName, firstName);
				System.out.println("user分隔符====》》》"+resultUser.getName());
			}		
		
		
	}
	
	private void mian() {
		// TODO Auto-generated method stub
	
	}
	public static void main(String[] args) {
		//将json字符串转化成json数组
		String result = "[{\"code\":\"B189493\",\"delFlag\":\"0\",\"email\":\"xin_gao22222@tianma.cn\",\"firstName\":\"GaoXin222\",\"flexAttrs\":{},\"mobile\":\"132622326\"}]";
	    List<WTUsers> users = JSON.parseArray(result, WTUsers.class);
	    for (WTUsers wtUsers : users) {
			System.out.println(wtUsers.getCode());
		}
		//System.out.println(parseObject);
		/*for(int i=0; i<jsonArray.size(); i++){  
		    //得到json数组中的每一个json对象
		    JSONObject obj = (JSONObject) jsonArray.get(i);  
		    //然后用Iterator迭代器遍历取值
		    Iterator it = obj.keys();  
		    while (it.hasNext()) {  
		      String key = it.next().toString();  
		      System.out.println("key ----->"+key);  
		      System.out.println("value ----->"+obj.get(key));  
		    }  
		} */ 
	}
}
